package io.bluerain.g4_tools.ui;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Toast;

import io.bluerain.android.sdk.update.core.utils.AttachUtils;
import io.bluerain.g4_tools.R;
import io.bluerain.g4_tools.ui.item.GmsFragment;
import io.bluerain.ldrawersample.DrawerMenuActivity;
import io.bluerain.ldrawersample.entities.Menu;

/**
 * Created by foredawn on 15-9-23.
 * 主程序入口
 */
public class MainActivity extends DrawerMenuActivity {

    private static String moreUrl = "http://bbs.gfan.com/android-8076222-1-1.html";
    private static String aboutUrl = "http://bbs.gfan.com/android-8074858-1-1.html";
    private static String domainUrl = "http://www.bluerain.io/source/g4_tools";
    private static String resourcesUrl = "http://pan.baidu.com/s/1mg2Bzfi";

    public static final Menu[] featureMenus = new Menu[]{
            new Menu(R.drawable.gms,
                    "GMS",
                    GmsFragment.class,
                    R.layout.main_activity),
            new Menu(R.drawable.icon,
                    "更多功能",
                    new Menu.ClickListener() {
                        @Override
                        public void onClick(Context context) {
                            toBrowser(context, moreUrl);
                        }
                    })
    };

    public static final Menu[] finalMenus = new Menu[]{

            new Menu(R.drawable.update, "检查更新", new Menu.ClickListener() {
                @Override
                public void onClick(Context context) {
                    Toast.makeText(context, "暂不支持手动检测更新，请重新启动应用自动检测更新", Toast.LENGTH_LONG).show();
                }
            }),
            new Menu(R.drawable.about, "关于", new Menu.ClickListener() {
                @Override
                public void onClick(Context context) {
                    AttachUtils.toBrowser(context, aboutUrl);
                }
            }),
            new Menu(R.drawable.download, "资源下载", new Menu.ClickListener() {
                @Override
                public void onClick(Context context) {
                    AttachUtils.toBrowser(context, resourcesUrl);
                }
            }),
            new Menu(R.drawable.creator, "作者", new Menu.ClickListener() {
                @Override
                public void onClick(Context context) {
                    AttachUtils.toBrowser(context, domainUrl);
                }
            }),
            new Menu(R.drawable.exit, "退出", new Menu.ClickListener() {
                @Override
                public void onClick(Context context) {
                    //退出整个应用程序
                    android.os.Process.killProcess(android.os.Process.myPid());
                    System.exit(0);
                }
            })
    };

    public MainActivity() {

        super(featureMenus, finalMenus,
                "G4工具箱",
                "你为什么不尝试一下侧滑菜单呢？", 0);
    }

    public static void toBrowser(Context context, String url) {
        Uri uri = Uri.parse(url);
        Intent downloadIntent = new Intent(Intent.ACTION_VIEW, uri);
        context.startActivity(downloadIntent);
    }

}